<template>
	<div class="payment">
		<div class="template" v-show="loading">
			<div><mt-spinner :type="3" :size="60"></mt-spinner></div>
		</div>
		<div class="header">支付订单</div>
		<div class="pay">
			需支付：<span>{{actualMoney}}元</span>
		</div>
		<div class="paymentfloor">
			<img src="../assets/pay.png"> 微信安全支付
		</div>
		<button @click="pay">确认支付</button>
	</div>
</template>

<script>
	import { BaseUrl } from '../Baseurl/common.js';
	import { Toast } from 'mint-ui';
	export default{
		data(){
			return{
				actualMoney:'',
				loading:true,
				orderNo:'',
				descript:'',
				platform:'',
				notifyUrl:''
			}
		},
		created(){
			this.orderNo = this.$route.query.orderNo;
			this.descript = this.$route.query.descript;
			this.actualMoney = this.$route.query.actualMoney;
			this.platform = this.$route.query.platform;
			this.notifyUrl = this.$route.query.notifyUrl;
			if(this.orderNo =='' || this.descript=="" || this.actualMoney =="" || this.platform == ""){
				this.loading = false;
				Toast({
					message: '地址不正确',
					position: 'middle',
					duration: 3000
				})
			}else{
				var url = BaseUrl + 'wxpay/platform/payH5?orderNo=' + this.orderNo + '&descript=' + this.descript + '&actualMoney=' + this.actualMoney + '&platform=' + this.platform + '&notifyUrl= ' + this.notifyUrl;
				this.$http.get(url).then(res=>{
					if(res.data.code == '10000'){
						this.loading = false;
						this.prepay_id = res.data.data.prepay_id;
						this.packages = res.data.data.timestamp;
					}else{
						this.loading = false;
						Toast({
							message: res.data.msg,
							position: 'middle',
							duration: 3000
						})
					}
					
				})
			}
				
		},
		methods:{
			pay:function(){
				//var Url = encodeURI('http://wap.uhuijia.com.cn/#/paysuccess')
				//console.log(Url)
				//window.location.href  = http%3a%2f%2fwap.uhuijia.com.cn%2f%23%2fpaysuccess;
				window.location.href  = 'https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?&prepay_id=' + this.prepay_id + '&package=' +this.packages + '&redirect_url=http%3a%2f%2fwap.uhuijia.com.cn%2f%23%2fpaysuccess';
			}
		}
	}
</script>

<style scoped="scoped">
	.template{
		width: 100%;
		height: 100%;
		background: rgba(0,0,0,0.5);
		position: absolute;
		z-index: 99;
	}
	.template div{
		position: absolute;
		top: 5.5rem;
		left: 50%;
		margin-left: -0.6rem;
	}
	.payment{
		background: #F0F0F0;
	}
	.header{
		height: 0.6rem;
		line-height: 0.6rem;
		background: #F0F0F0;
		font-size: 0.3rem;
		text-align: center;
		color: #212121;
	}
	.pay{
		background: #fff;
		text-align: right;
		padding: 0.3rem 0.2rem;
		color: #D1D1D1;
	}
	.pay span{
		color: #FF2040;
	}
	.paymentfloor{
		display: flex;
		align-items: center;
		padding: 0.3rem 0.3rem;
		border-bottom: 1px solid #CCCCCC;
		font-size: 0.3rem;
	}
	.paymentfloor img{
		margin-right: 0.2rem;
	}
	.payment button{
		width: 100%;
		padding: 0.3rem 0;
		background: #FF2040;
		color: #fff;
		border: none;
		outline: none;
		position: fixed;
		left: 0;
		bottom: 0;
	}
</style>